//
//  catagoryViewController.swift
//  HMXMeiTuan
//
//  Created by apple on 16/7/20.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class catagoryViewController: UIViewController {

    //懒加载分类栏的左右tableView
    private lazy var doubletableView : doubleTableView = doubleTableView.viewForXib()
    //懒加载可变数组catagory
    private lazy var catagory : [catagoryItem] = [catagoryItem]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        preferredContentSize = CGSize(width: 320, height: 480)
        
        setUpcatagoryVC()
        
        loadData()
        
        
    }
}

//MARK:- 用于初始化左右的tableView
extension catagoryViewController{
    
    func setUpcatagoryVC(){
        
        //添加tableView
        view.addSubview(doubletableView)
        
        //设置tableView的frame
        doubletableView.frame = view.bounds
    
    }
}

//MARK:- 用于加载数据
extension catagoryViewController{
    
    private func loadData(){
        
        let catagoryPath = NSBundle.mainBundle().pathForResource("categories.plist", ofType: nil)!
        
        guard let catagortArr = NSArray(contentsOfFile: catagoryPath)as? [[String: NSObject]] else{
            return
        }
        
        for dict in catagortArr{
            
            catagory.append(catagoryItem(dict: dict))
        }
        
        doubletableView.catagory = catagory
        
    }
}